#pragma once
#include "uimanager.h"
#include <tchar.h>
#include <time.h>

struct ColorPickerAttribute
{
	DWORD m_hotBorderColor;
	DWORD m_normalBorderColor;
	DWORD m_itemWidth;
	DWORD m_itemHeight;
	DWORD m_itemPadding;
	DWORD m_minItemCount;
	CStdString m_dropdwonArrowImage;

	ColorPickerAttribute()
	{
		m_hotBorderColor = 0xFF85E4FF;
		m_normalBorderColor = 0xFF4EA0D1;
		m_itemWidth = 15;
		m_itemHeight = 15;
		m_itemPadding = 3;
		m_minItemCount = 16;
		m_dropdwonArrowImage = _T("");
	}
};

class CColorItemUI : public CControlUI
{
public:
	CColorItemUI()
	{
		m_ItemState = 0;
		m_hotBorderCorlor = 0xFF85E4FF;
		m_normalBorderColor = 0xFF4EA0D1;
		m_dwBackColor = 0xFFFFFFFF;
	}
	
	void SetFixedHeight(int cy)
	{
		m_cxyFixed.cy = cy;
	}

	void SetFixedWidth(int cx)
	{
		m_cxyFixed.cx = cx;
	}

	void Event(TEventUI& event);

	void PaintBorder(HDC hDC);

	void PaintText(HDC hDC);

	void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);

	void SetHotBorderColor( DWORD color )
	{
		if (m_hotBorderCorlor == color)
			return;

		m_hotBorderCorlor = color;
		Invalidate();
	}

	void SetNormalBorderColor( DWORD  color )
	{
		if (m_normalBorderColor == color)
			return;

		m_normalBorderColor = color;
		Invalidate();
	}

private:
	DWORD m_normalBorderColor;
	DWORD m_hotBorderCorlor;
	
	DWORD m_ItemState; //hot or not
};




//////////////////////////////////////////////////////////////////////////
// 
//
//////////////////////////////////////////////////////////////////////////


class CColorPickerWnd;

class CColorPickerUI :
	public CContainerUI
{
	friend CColorPickerWnd;
public:
	CColorPickerUI(void);
	~CColorPickerUI(void);

	void Event(TEventUI& event);

	void ShowColorPannel();

	void ShowColorDialog();

	void DoPaint(HDC hDC, const RECT& rcPaint)
	{
		CControlUI::DoPaint(hDC, rcPaint);
	}

	void PaintBorder(HDC hDC);

	
	void PaintBkColor(HDC hDC);

	void SetPos(RECT rc)
	{
		CControlUI::SetPos(rc);
	}

	void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);

private:
	CColorPickerWnd* m_pPickerWnd;

	DWORD m_normalBorderColor;
	DWORD m_hotBorderCorlor;

	DWORD m_ItemState; //hot or not

};


//////////////////////////////////////////////////////////////////////////
// 
//
//////////////////////////////////////////////////////////////////////////


class CColorPickerWnd : public CWindowWnd, public INotifyUI
{
public:
	CColorPickerWnd(){}

	UINT GetClassStyle()
	{
		return 0;//UI_CLASSSTYLE_DIALOG;
	}


	void Notify(TNotifyUI& msg);

	LPCTSTR GetWindowClassName() const
	{
		return _T("ColorPickerWnd");
	}

	LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);

	void OnFinalMessage(HWND hWnd)
	{
		//release resource
		if (m_pOwner)
		{
			m_pOwner->m_pPickerWnd = NULL;
			m_pOwner->m_ItemState = 0;
			m_pOwner->Invalidate();
		}
		delete this;
	}

	void Init(CColorPickerUI* pOwner);

	void PopulateItem( int count );
	

private:
	CColorPickerUI* m_pOwner;
	CPaintManagerUI m_pm;
	CVerticalLayoutUI* m_pVerticalLayout;
};

//////////////////////////////////////////////////////////////////////////
// 
//
//////////////////////////////////////////////////////////////////////////
